package com.dragon.mmochat.message;

import java.util.ArrayList;
import java.util.List;

import com.dragon.mmochat.MmochatConstant;
import com.dragon.mmochat.model.MmochatServerInfo;
import com.dragon.mmochat.util.MmochatUtil;
import com.skymobi.buffer.SkymobiBuffer;
import com.skymobi.message.SkymobiProtocolMessage;

public class Mmochat_1_11S extends SkymobiProtocolMessage {
	int hallState;
	List<MmochatServerInfo> serverList;

	public Mmochat_1_11S() {
		setMsgCode(MmochatConstant.MSGCODE_MMOCHAT_S_1_11);
	}

	@Override
	protected void encodeBody(SkymobiBuffer out) {
		out.putUnsignedShort(hallState);
		out.putShort((short) serverList.size());
		for (MmochatServerInfo server : serverList) {
			out.putInt(server.getId());
			out.putPrefixedString(server.getName(), 1);
			out.putInt(server.getModuleInstID());
			if (server.isNewServer()) {
				out.put((byte) 1);
			} else {
				out.put((byte) 0);
			}
			out.put((byte) MmochatUtil.getServerHotType(server.getPlayerNum())
					.getValue());
			out.put((byte) server.getState().getKey());
			String stopMsg = server.getStopMsg();
			if (stopMsg == null) {
				out.putShort((short) 0);
			} else {
				out.putPrefixedString(stopMsg, 2);
			}
		}
	}

	public void setHallState(int hallState) {
		this.hallState = hallState;
	}

	public void setServerList(List<MmochatServerInfo> serverList) {
		this.serverList = new ArrayList<MmochatServerInfo>(serverList);
	}

}